" An example for a vimrc file.
"
" Maintainer:   Bram Moolenaar <Bram@vim.org>
" Last change:  2011 Apr 15
"
" To use it, copy it to
"     for Unix and OS/2:  ~/.vimrc
"             for Amiga:  s:.vimrc
"  for MS-DOS and Win32:  $VIM\_vimrc
"           for OpenVMS:  sys$login:.vimrc

" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
  finish
endif

" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

if has("vms")
  set nobackup      " do not keep a backup file, use versions instead
else
  set backup        " keep a backup file
endif

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" Don't use Ex mode, use Q for formatting
map Q gq

" CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>

" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
  set mouse=a
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  " Also don't do it when the mark is in the first line, that is the default
  " position when opening a file.
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

  augroup END

else

  set autoindent        " always set autoindenting on

endif " has("autocmd")

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
  command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
          \ | wincmd p | diffthis
endif

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Vim editor settings.
" :help
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Start Vim with a maximized window.
" :help gui-win32-maximized
au GUIEnter * simalt ~x

" Describe what components and options of the GUI should be used.
" :help 'guioptions'
set guioptions-=T
set guifont=Courier\ New:h12

" Specify the label to display for each tab page.
" %N - Tab page number.
" %t - Name (tail) of active file in the buffer.
" %h - Help buffer flag, text is "[help]".
" %r - Readonly flag, text is "[RO]".
" %m - Modified flag, text is "[+]"; "[-]" if 'modifiable' is off.
" :help 'guitablabel'
" :help 'statusline'
set guitablabel=%N.\ %t%h%r%m

" Set the color scheme.
" :help :colorscheme
colorscheme softgreen

" Show the line and column number of the cursor position, separated by a comma.
" help 'ruler'
set ruler

" Print the line number in front of each line.
" :help 'number'
set number

" Show (partial) command in the last line of the screen.
" :help 'showcmd'
set showcmd

" If in Insert, Replace or Visual mode put a message on the last line.
" :help 'showmode'
set showmode

" Set no wrap display.
" :help 'wrap'
set nowrap

" Set backup options.
" :help 'backup'
" :help 'writebackup'
set nobackup            " Don't keep the backup file.
set writebackup         " Backup the current file before writting.

" Enable file type detection.
" :help :filetype
filetype on

" Copy indent from current line when starting a new line (typing <CR>
" in Insert mode or when using the "o" or "O" command).
" :help 'autoindent'
set autoindent

" A history of ":" commands, and a history of previous search patterns
" are remembered.
" :help 'history'
set history=50

" Set the maximum width of text.
" :help 'textwidth'
set textwidth=100

" While typing a search command, show where the pattern, as it was typed
" so far, matches.
" :help 'incsearch'
set incsearch

" Set the size of windows.
" Notice: 'winminheight' and 'winminwidth' should be set earlier than
"         'winheight' and 'winwidth'.
" :help 'winheight'
" :help 'winminheight'
" :help 'winwidth'
" :help 'winminwidth'
" :help 'equalalways'
set winminheight=1      " Minimal height of other windows.
set winminwidth=1       " Minimal width of other windows.
set winheight=1         " Minimal height of the current window.
set winwidth=20         " Minimal width of the current window.
set equalalways         " Make all the windows the same size
                        " after splitting or closing a window.

" Set the width of <TAB>.
" :help 'tabstop'
" :help 'shiftwidth'
" :help 'softtabstop'
" :hlep 'expandtab'
set tabstop=4           " Number of spaces the existed <Tab> counts for.
set shiftwidth=4        " Number of spaces to use for (auto)indent.
set softtabstop=4       " Number of spaces to use for <Tab> and <BS>.
set expandtab           " Use spaces to insert a <Tab>.

" Set help language.
" :help 'helplang'
set helplang=cn,en

" Set the path of work directory.
" :help 'path'
set path=.

" Map <F7> to change colorscheme.
" map <F7> :colorscheme <Tab><CR>

" Map <F9> to search.
" vnoremap <F9> y:exe "grep /" . escape(@", '\\/') . "/ *.c *.h"<CR>

" Set character encoding.
set fileencodings=utf-8,gb2312,gbk,gb18030
set termencoding=utf-8

set fileformat=unix
set fileformats=unix,dos


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" cindent settings.
" :help 'cindent'
" :help 'cinoptions'
" :help cinoptions-values
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Place case labels N characters from the indent of the switch().
" help cino-:
set cinoptions=:0


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Netrw plugin settings.
" :help netrw
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Set the tree style as the default listing style.
" :help netrw-i
let g:netrw_liststyle=0

" Specify initial size of new windows made with "o" (see netrw-o),
" "v" (see netrw-v), :Hexplore or :Vexplore.
" :help g:netrw_winsize
let g:netrw_winsize=70

" Control right/left splitting when using "v"(see netrw-v).
" :help g:netrw_altv
let g:netrw_altv=0


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" ctrlp plugin settings.
" :help ctrlp-contents
" :help ctrlp-mappings to see key maps when using ctrlp plugin
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" set display style when opening multiple files
let g:ctrlp_open_multiple_files = 'hr'

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Cscope settings.
" :help cscope
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" when using :tag or ctrl-], actually execute :cstag,
" will search both tags file and cscope database
set cscopetag

" when using :cstag, search cscope database first, and then tags file
set cscopetagorder=0

" show full file path of cscope find result
set cscopepathcomp=0

" cscope hot key map
nmap <C-\><C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-\><C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-\><C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-\><C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-\><C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-\><C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-\><C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-\><C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>

" Using 'CTRL-\' then a search type makes the vim window
" split horizontally, with search result displayed in
" the new window.
nmap <C-\>s :scs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>g :scs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>c :scs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>t :scs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>e :scs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>f :scs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-\>i :scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-\>d :scs find d <C-R>=expand("<cword>")<CR><CR>

" Hitting CTRL-space *twice* before the search type does a vertical
" split instead of a horizontal one
nmap <C-Space><C-Space>s :vert scs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-Space><C-Space>g :vert scs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-Space><C-Space>c :vert scs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-Space><C-Space>t :vert scs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-Space><C-Space>e :vert scs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-Space><C-Space>i :vert scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-Space><C-Space>d :vert scs find d <C-R>=expand("<cword>")<CR><CR>

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Ctags plugin settings.
" :help ctags
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Set the path of tags file.
" :help 'tags'
set tags=c:\brook\work\work\linux\linux\tags

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Taglist plugin settings.
" Run the ":helptags {dir}" command first to process the taglist help file,
" where {dir} is the directory of taglist's help file <taglist.txt>.
" :help taglist.txt
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Specify the location (path) of the exuberant ctags utility.
" :help 'Tlist_Ctags_Cmd'
let Tlist_Ctags_Cmd='C:\Brook\program\ProfessionalProgram\Vim\vimfiles\plugin\ctags\ctags.exe'

" Automatically open the tags tree for the current buffer and close all the
" other buffers.
" :help 'Tlist_File_Fold_Auto_Close'
let Tlist_File_Fold_Auto_Close=1

" When a new file is edited, the tags defined in the file are automatically
" processed and added to the taglist.
" :help 'Tlist_Auto_Update'
let Tlist_Auto_Update=1

" Display the tags defined only in the current buffer.
" :help 'Tlist_Show_One_File'
let Tlist_Show_One_File=1

" Specify the default width of the vertically split taglist window.
" :help 'Tlist_WinWidth'
let Tlist_WinWidth=33

" Create a normal mode mapping for the <F8> key to toggle the taglist window.
" :help taglist-using
nnoremap <silent> <F8> :TlistToggle<CR>

" Set ignore files or directories when using :vimgrep
" :help wildignore
set wildignore+=tags,*.o,*.obj

cd c:\brook\work\work\linux\linux

" add cscope database
cscope add c:\brook\work\work\vim\linux\cscope.out
